<?php

declare(strict_types=1);

namespace App\Controller;

use App\Model\AccountModel;

class IndexController
{
    public function index(\Swoole\Http\Request $request, \Swoole\Http\Response $response)
    {
        $response->end(
            json_encode(
                [
                    'method'  => $request->server['request_method'],
                    'message' => 'Hello gg.',
                ]
            )
        );
    }

    public function hello($request, $response, $data)
    {
        $name = $data['name'] ?? 'gg';

        $response->end(
            json_encode(
                [
                    'method'  => $request->server['request_method'],
                    'message' => "Hello {$name}.",
                ]
            )
        );
    }

    public function pdo($request, $response)
    {
        $result = (new AccountModel())->select("co_account", "*");
        $response->end(json_encode($result));
    }
}
